﻿using UnityEngine;
using System.Collections;

public class EnemyPlane : Plane  {

		private Rigidbody2D rig;

		public GameObject bulletPrefab;
		public AudioClip ShootSond;
		private AudioSource audioSource;
		public float shootlnterval=1f;
	    public float speed=5f;

	protected  override  void Start () {


		base.Start ();
		rig = GetComponent<Rigidbody2D> ();

		audioSource = gameObject.AddComponent <AudioSource > ();
		rig.velocity = Vector2.down * speed;
		if (bulletPrefab != null) {
			InvokeRepeating ("Shoot", Random.Range (0f, 1f), shootlnterval);
		} else {
			rig.AddTorque (Random.Range (0, 2) == 0 ? 100 : -100);
		}	
	}
		void Shoot()
		{
			Instantiate (bulletPrefab ,transform.position ,transform .rotation);
			audioSource.PlayOneShot (ShootSond);
		}
			
}
